package graduate.wangyaqi.SeveralQuestions;

import graduate.wangyaqi.OnlyQuestions.OnlyQuestions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Optional;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping(path="/ServeralQuestions")
public class SeveralQuestionsController {
    @Autowired
    private SeveralQuestionsService severalQuestionsService;

    @GetMapping(path="/getAllByTaotiID")
    public Iterable<SeveralQuestions> getAllByTaotiID(int id){
        Iterable<SeveralQuestions> list= severalQuestionsService.getAllByTaotiID(id);
        return list;
    }

    @GetMapping(path="/delete")
    public @ResponseBody
    void Del(Long id) {
        severalQuestionsService.delete(id);
    }

    @PostMapping(path="/save")
    public boolean save(@RequestBody SeveralQuestions severalQuestions){
        severalQuestions.setJointime(new Date());
        severalQuestionsService.save(severalQuestions);
        return true;
    }

    @GetMapping(path="/findById")
    public Optional<SeveralQuestions> findById(Long aLong){
        return severalQuestionsService.findById(aLong);
    }
}
